package com.tianma315.admin.device.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.common.base.CoreServiceImpl;
import org.springframework.stereotype.Service;

import com.tianma315.admin.device.dao.MaintainTypeDao;
import com.tianma315.admin.device.domain.MaintainTypeDO;
import com.tianma315.admin.device.service.MaintainTypeService;

import java.util.List;

/**
 * 
 * <pre>
 * 设备维护类型
 * </pre>
 * <small> 2019-05-22 16:08:48 | Aron</small>
 */
@Service
public class MaintainTypeServiceImpl extends CoreServiceImpl<MaintainTypeDao, MaintainTypeDO> implements MaintainTypeService {

    @Override
    public Page<MaintainTypeDO> getMaintainTypeDOPage(Integer pageNumber, Integer pageSize, MaintainTypeDO maintainTypeDTO) {
        // 查询列表数据
        Page<MaintainTypeDO> page = new Page<>(pageNumber, pageSize);

        Wrapper<MaintainTypeDO> wrapper = new EntityWrapper<MaintainTypeDO>();
        wrapper.eq("state",0).like("maintain_name",maintainTypeDTO.getMaintainName());
        wrapper.orderBy("maintain_type_id",false);
        page = selectPage(page, wrapper);
        int total = selectCount(wrapper);
        page.setTotal(total);
        return page;
    }

    @Override
    public boolean addMaintainTypeDO(MaintainTypeDO maintainTypeDO) {
        maintainTypeDO.setState(0);
        return insert(maintainTypeDO);
    }

    @Override
    public boolean deleteMaintainTypeDO(Integer id) {
        MaintainTypeDO maintainTypeDO = new MaintainTypeDO();
        maintainTypeDO.setMaintainTypeId(id);
        maintainTypeDO.setState(1);
        return updateById(maintainTypeDO);
    }

    @Override
    public List<MaintainTypeDO> getMaintainTypeDOList() {
        Wrapper<MaintainTypeDO> wrapper = new EntityWrapper<MaintainTypeDO>();
        wrapper.eq("state",0);
        List<MaintainTypeDO> maintainTypeDOList = selectList(wrapper);
        return maintainTypeDOList;
    }
}
